package com.jt.tenant.db;

import android.content.Context;

import com.jt.tenant.conn.GetDiagnosticCar;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/4/18.
 */
public class ErrorData {

    public static List<GetDiagnosticCar.Detection> GetData(Context context){

        List<GetDiagnosticCar.Detection> list = new ArrayList<>();

        LinkedHashMap<String, GetDiagnosticCar.Detection> map = new LinkedHashMap<String, GetDiagnosticCar.Detection>();

        try {

            InputStreamReader isr = new InputStreamReader(context.getAssets().open("error_code.csv"));

            BufferedReader reader = new BufferedReader(isr);

            String line = null;

            while ((line = reader.readLine()) != null) {

                String item[] = line.split(",");

                if (item[0].equals("code") || item[1].equals("description")) continue;

                if(!map.containsKey(item[0])){

                    GetDiagnosticCar.Detection error = new GetDiagnosticCar.Detection();

                    error.code = item[0];

                    error.description = item[1];

                    map.put(error.code, error);

                }

            }

        } catch (IOException e1) {

            e1.printStackTrace();

        }

        for (Map.Entry<String, GetDiagnosticCar.Detection> entry : map.entrySet()) {

            list.add(entry.getValue());

        }

        return list;

    }

}
